#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

class Solution {
    public:
        vector<int> plusOne(vector<int> &digits) {
            vector<int> ans;                            
            if (digits.size() == 0) {ans.push_back(1); return ans;}
            reverse(digits.begin(), digits.end());
            int carry = 0;
            for (int i = 0; i < digits.size(); i++) {
                int sum = digits[i] + (i == 0 ? 1 : 0) + carry;
                if (sum > 9) { sum -= 10; carry = 1;}
                else carry = 0;
                ans.push_back(sum);
            }
            if (carry) ans.push_back(1);
            reverse(ans.begin(), ans.end());
            return ans;
        }
};


//test in 1337 online judge and pass all the test
int main(int argc, char **argv)
{
    Solution mySolution;
    vector<int> input;
    input.push_back(1);
    input.push_back(2);
    input.push_back(2);
    vector<int> ans;

    cout << "-----------------Test 1--------------------" << endl;
    ans = mySolution.plusOne(input);
    for (int i = 0; i < ans.size(); i++) 
        cout << ans[i] << " " ;


    cout << "-----------------Test 2--------------------" << endl;


    cout << "-----------------Test 3--------------------" << endl;


    cout << "-----------------Test 4--------------------" << endl;


    cout << "-----------------Test 5--------------------" << endl;



}
